package com.neuedu.his.dao;

import com.neuedu.his.entity.Role;
import com.neuedu.his.framework.BaseDao;
import com.neuedu.util.JDBCUtil;

import java.util.List;

/**
 * 项目：      his
 * 类名:       RoleDao
 * 创建时间：  2020/12/23  8:43
 * 描述 :     用户数据访问层
 * 作者 :     张金山
 * QQ :     314649444
 * Site:      https://jshand.gitee.io
 */
public class RoleDao implements BaseDao<Role> {


    @Override
    public List<Role> selectList(String sql, Object... args) {
        return JDBCUtil.executeQuery(sql, Role.class, args);
    }

    @Override
    public Role selectById(Integer id) {
        String sql = " select * from role where Role_id = ?";
        return JDBCUtil.getOne(sql, Role.class, id);
    }

    @Override
    public boolean update(Role role) {

       String sql  = " UPDATE   role SET   role_name = ?,   active = ? WHERE role_id = ? ";

        return JDBCUtil.executeUpdate(sql,
                role.getRoleName(),
                role.getActive(),
                role.getRoleId()
        );
    }


    /**
     * 逻辑删除，没有真正删除数据
     * @param id
     * @return
     */
    @Override
    public boolean deleteById(Integer id) {

        String sql = " update  role set active = 0 where role_id  = ? ";

        return JDBCUtil.executeUpdate(sql,id);
    }

    @Override
    public boolean batchDel(String sql, Object... parm) {
        return false;
    }

    @Override
    public boolean insert(Role role) {
        String sql = " INSERT INTO role(   role_name )  VALUES ( ? )  ";
        return JDBCUtil.executeUpdate(sql, role.getRoleName());
    }


}
